import java.util.*;

public class Main {

    public static void main(String[] args) {
        MyHashBucket<Integer,Integer> myHashMap = new MyHashBucket<>();
        myHashMap.put(1,10);
        myHashMap.put(2,20);
        myHashMap.put(7,30);
        myHashMap.put(6,40);
        myHashMap.put(5,50);
        myHashMap.put(9,60);

        System.out.println(myHashMap.get(3));
        System.out.println(myHashMap.get(9));
    }
    public int firstUniqChar(String s) {
       Map<Character,Integer> map = new TreeMap<>();

        for(int i = 0; i < s.length();i++){
            if(map.containsKey(s.charAt(i))){
                map.put(s.charAt(i),map.getOrDefault(s.charAt(i),0) + 1);
                continue;
            }
            map.put(s.charAt(i),1);
        }

        for(int j = 0;j < s.length();j++){
            if(map.get(s.charAt(j)) == 1){
                return j;
            }
        }
        return -1;
    }

    public static void main6(String[] args) {
        Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(2);
        set.add(3);

        int len = set.size();
        System.out.println(set.contains(2));

        Collection<Integer> collection = set;

        Set<Integer> set1 = new HashSet<>();

        set1.addAll(collection);
        for(Integer i : set1){
            System.out.print(i + " ");
        }

    }

    public static void main5(String[] args) {
        Map<Integer,Integer> map = new TreeMap<>();
        map.put(1,88);
        map.put(2,99);
        map.put(3,70);
        map.put(3,44);
        //keySet方法是防止key值在Set中返回
        for(Integer key : map.keySet()){
            System.out.print(key + " ");
        }
        System.out.println();
        for(Map.Entry<Integer,Integer> entry : map.entrySet()){
//            System.out.println("key:" + entry.getKey() + "---》value:" + entry.setValue(entry.getValue()+ 1));
           entry.setValue(entry.getValue()+ 1);
            System.out.println("key:" + entry.getKey() + "---》value:" + entry.setValue(entry.getValue()+ 1));
        }
    }

    //Map的使用方法
    public static void main4(String[] args) {
        Map<Integer,Integer> map = new TreeMap<>();
        map.put(1,88);
        map.put(2,99);
        map.put(3,70);
        map.put(3,44);

        System.out.println(map.get(1));
        System.out.println(map.getOrDefault(4,666));

        System.out.println(map.remove(1));

        Set<Integer> set = map.keySet();
        for(Integer key : set) {
            System.out.print(key + " ");
        }
        System.out.println();
        Collection<Integer> collection = map.values();
        for(Integer value : collection) {
            System.out.print(value + " ");
        }
        System.out.println();
        System.out.println(map.containsKey(1));
        System.out.println(map.containsKey(4));
        System.out.println(map.containsValue(22));
        System.out.println(map.containsValue(70));


        Set<Map.Entry<Integer,Integer>> entrySet = map.entrySet();
        for(Map.Entry<Integer,Integer> entry : entrySet){
            Integer key = entry.getKey();
       Integer value = entry.getValue();
            System.out.println("key:"  + key + " value:" + value);

        }
        System.out.println();

        Iterator<Integer> iterator = map.values().iterator();
        while(iterator.hasNext()){
            System.out.print(iterator.next() + " ");
        }
    }

    //Map.Entry接口的使用
    public static void main3(String[] args)throws UnsupportedOperationException {

        Map.Entry<Integer,Integer> map = Map.entry(10,20);

        System.out.println(map.getKey());
        System.out.println(map.getValue());
        try{
            //异常原因是应为map是一个接口的引用，并没有真正实现setValue方法
            map.setValue(21);
        }catch (UnsupportedOperationException e){
            System.out.println(map.getValue());
        }

        //System.out.println(map.getValue());
    }
    public static void main2(String[] args) {
        int[] arr = {1,6,3,10,7,8,11};
        //int[] arr = {1,9,3,10,11};
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        for (int i = 0; i < arr.length; i++) {
            binarySearchTree.put(arr[i]);
        }
        binarySearchTree.remove(6);
        //binarySearchTree.remove(9);
    }
    public static void main1(String[] args) {
        int[] arr = {1,3,9,4,10,11};
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        for (int i = 0; i < arr.length; i++) {
            binarySearchTree.put(arr[i]);
        }
        System.out.println(binarySearchTree.search(11).key);
    }
}